<template>
	<view class="home">
		<fixed>
			<tab class="tabs" @change="handerTabChange" :list="tabList" :activeIndex="activeIndex*1" activeColor="#606DCE"
				width="33.3%" height="100rpx"></tab>
			<view class="b-1px-b"></view>
		</fixed>
		<view class="padding-20">
			<view v-for="(item,index) in couponList" :key="index" class="cou_item">
				<view class="left">
					<template v-if="item.type=='discount'">
						<view class="cou_price">{{item.discount}}</view>
						<view style="height: 100%;padding-top: 20rpx;">
							<view class="title">{{item.name}}</view>
							<view class="tips u-flex-center">满{{item.limit}}打{{item.discount}}折</view>
							<view class="time">
								到期时间：
								<view>{{item.enddate}}</view>
							</view>
						</view>
					</template>
					<template v-if="item.type=='reduction'">
						<view class="cou_price">{{item.price}}</view>
						<view style="height: 100%;padding-top: 20rpx;">
							<view class="title">{{item.name}}</view>
							<view class="tips u-flex-center">满{{item.limit}}减{{item.price}}</view>
							<view class="time">
								到期时间：
								<view>{{item.enddate}}</view>
							</view>
						</view>
					</template>
				</view>
				<view class=" u-flex-center" :class="activeIndex==0?'status':'guobtn'" @click="goStore(item.shop_id)">
					{{activeIndex==0 ? '立即使用' :activeIndex==1 ? '已使用': '已过期'}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeIndex: 0,
				tabList: [{
					title: '待使用',
					id: 1
				}, {
					title: '已使用',
					id: 2,
				}, {
					title: '已过期',
					id: 3
				}],
				couponList: []
			}
		},
		onReady() {
			this.getList()
		},
		methods: {
			handerTabChange(index) {
				this.activeIndex = index;
				this.getList()
			},
			getList() {
				this.$u.post('/api/wanlshop/coupon/getMyList', {
					state: this.activeIndex + 1
				}).then(res => {
					if (res.code == 1) {
						this.couponList = res.data.data
					}
				})
			},
			goStore(id){
				if(this.activeIndex ==0){
					uni.navigateTo({
						url:'/wNew/pages/store?id=' + id
					})
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.home {
		width: 100%;
		min-height: 100vh;
		background: #f6f6f6;
	}

	.padding-20 {
		padding: 20rpx;
	}

	.cou_item {
		margin-bottom: 40rpx;
		position: relative;
		width: 100%;
		height: 210rpx;
		overflow: hidden;
		border-radius: 30rpx;
		background: #fff;

		.left {
			width: 471rpx;
			height: 210rpx;
			background: #fff;
			padding: 27rpx 40rpx 0rpx 30rpx;
			display:flex;
			justify-content: space-between;
			// border: 1px solid #000;
			align-items: center;

			.code {
				font-size: 22rpx;
				color: #666666;
			}

			.cou_price {
				margin-right: 25rpx;
				color: #E55D23;
				font-size: 88rpx;
				font-weight: 550;

				text {
					margin-top: 32rpx;
					font-size: 26rpx;
					margin-right: 10rpx;
				}
			}

			.title {
				font-size: 26rpx;
				font-weight: bold;
				color: #333333;
			}

			.tips {
				margin-top: 10rpx;
				width: 154rpx;
				height: 31rpx;
				background: #E55D23;
				font-size: 20rpx;
				color: #FFFFFF;
			}

			.time {
				height: 20rpx;
				font-size: 22rpx;
				color: #666666;
				margin-top: 35rpx;
			}
		}

		.status {
			width: 220rpx;
			height: 210rpx;
			position: absolute;
			right: 0;
			top: 50%;
			transform: translateY(-50%);
			font-size: 30rpx;
			font-weight: bold;
			color: #fff;
			background: #606DCE;
		}
		.guobtn{
			width: 220rpx;
			height: 210rpx;
			position: absolute;
			right: 0;
			top: 50%;
			transform: translateY(-50%);
			font-size: 30rpx;
			font-weight: bold;
			color: #fff;
			background: #989898;
		}
	}
</style>